package com.chefu.order.controller;

import com.chefu.common.pojo.PageResult;
import com.chefu.order.dto.OrderDTO;
import com.chefu.order.pojo.Order;
import com.chefu.order.pojo.Record;
import com.chefu.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 服务订单
 */
@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 创建订单
     * @param orderDTO
     * @return
     */
    @PostMapping("/order/summit")
    public ResponseEntity<Long> buildOrder(@RequestBody OrderDTO orderDTO){
       Long orderId = orderService.buildOrder(orderDTO);
        System.out.println(orderId);
       return ResponseEntity.ok(orderId);
    }

    /**
     * 条件过滤分页查询订单
     */
    @GetMapping("/order/page")
    public ResponseEntity<PageResult<Order>> findByPage(
            @RequestParam(value = "pageNo",defaultValue = "1") Integer pageNo,
            @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
            @RequestParam(value = "orderServiceId",required = false) Long orderServiceId,
            @RequestParam(value = "orderPerson",required = false) String orderPerson,
            @RequestParam(value = "shortName",required = false) String shortName,
            @RequestParam(value = "startTime",required = false) String startTime,
            @RequestParam(value = "endTime",required = false) String endTime,
            @RequestParam(value = "orderStatus",required = false) String orderStatus,
            @RequestParam(value = "payStatus",required = false) String payStatus
    ){
          PageResult<Order> pageResult = orderService.findByPage(pageNo,pageSize,orderServiceId,orderPerson,shortName,startTime,endTime,orderStatus,payStatus);
          return ResponseEntity.ok(pageResult);
    }

    /**
     *  订单状态发生改变
     */
    @PutMapping("/order/change")
    public ResponseEntity<Void> changeStatus(
            @RequestParam("orderServiceId") Long orderServiceId,
            @RequestParam("orderStatus") String orderStatus,
            @RequestParam("merchantId") Long merchantId,
            @RequestParam("employeeName") String employeeName
    ){
        orderService.changeStatus(orderServiceId,orderStatus,merchantId,employeeName);
        return ResponseEntity.ok().build();
    }
}
